<!--#include file="../../../easyasp/easp.asp" -->
<%
Easp.NoCache
easp.var("username")=session("username")
mc
dim rs,MyArray
	set rs=easp.db.sel("select sum(jf) from [jf] where jsr={username} and qrjf=1")
	if rs.RecordCount >= 1 then	
		MyArray= rs.getrows()
		easp.var("myjf")=MyArray(0,0)
	end if
	set rs=nothing

	set rs=easp.db.sel("select sum(jf) from [jf] where jsr={username} and qrjf=0")
	if rs.RecordCount >= 1 then	
		MyArray= rs.getrows()
		easp.var("mywjf")=MyArray(0,0)
	end if
	set rs=nothing
	
Function mc
	dim ret,rs
	set rs=easp.db.sel("select mc,ljf,jxs from [user] where [username]={username}")
	if rs.RecordCount>=1 then
		easp.var("mc")=rs("mc")
		easp.var("ljf")=rs("ljf")
		easp.var("jxs")=rs("jxs")
	end if
	if Easp.Var("mc")="c" then
		Easp.Var("jxs")="admin"
	end if
End Function

%>
<!DOCTYPE html>
<html>
<head>
  <title>设置我的资料</title>
<%
	easp.include "h.asp"
%>
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">设置我的资料</div>
          <div class="layui-card-body" pad15>
            <blockquote class="layui-elem-quote layui-quote-nm">
未确认积分：<%=easp.var("mywjf")%> 
  <br>已确认积分：<%=easp.var("myjf")%>
</blockquote>	
            <div class="layui-form" lay-filter="">

              <div class="layui-form-item">
                <label class="layui-form-label">用户名：</label>
                <div class="layui-input-inline">
                  <input type="text" name="username" value="<%=session("username")%>" readonly class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">会员类别：</label>
                <div class="layui-input-block">
              <input type="radio" name="mc" value="p" title="会员" <%=Easp.IIF(easp.var("mc")="p", "checked", "")%>><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>会员</div></div>
              <input type="radio" name="mc" value="sp" title="代理" <%=Easp.IIF(easp.var("mc")="sp", "checked", "")%>><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>代理</div></div>
              <input type="radio" name="mc" value="c" title="经销商" <%=Easp.IIF(easp.var("mc")="c", "checked", "")%>><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>美容院</div></div>
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">兑换积分：</label>
                <div class="layui-input-inline">
                  <input type="text" id="dhtemp" name="dhtemp" value="<%=easp.var("myjf")%>" class="layui-input">
                  <input type="hidden" id="dhtemp2" name="dhtemp2" value="<%=easp.var("myjf")%>" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">此处输入要兑换的积分。兑换对象：<%=easp.var("jxs")%> </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit lay-filter="setjf">积分兑换</button>
                </div>
              </div>
            </div>
          </div>
        </div>
		<table id="user-manage" lay-filter="user-manage"></table>

      </div>
    </div>
  </div>

  <script src="../../layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set','table'],function(){
     var $ = layui.$
    ,setter = layui.setter
    ,admin = layui.admin
    ,form = layui.form
    ,table = layui.table; 
	
	table.render({
        elem: '#user-manage',
        url: layui.setter.base + 'lib/reg.asp?action=listjf_self&jsr=<%=session("username")%>',
        cols: [[
        {
            field: 'username',
            title: '积分来源',
            width: 100
        },
        {
            field: 'type',
            title: '积分类型',
            width: 100
        },	
        {
            field: 'qrjf',
            title: '审核',
            width: 60
        },		
        {
            field: 'jf',
            title: '积分',
            width: 90
        },
        {
            field: 'ins_time',
            title: '时间',
            width: 120
        }		
		]],
        id: 'user-manage',
        limit: 10,
        page: true,
        height: 475
    });
  
    form.render();
    form.on('submit(setjf)', function(obj){
			var txt=$("#dhtemp").val();
			$.ajaxSettings.async = false;				
			$.post(layui.setter.base + 'lib/reg.asp?action=havejf', { username: "<%=session("username")%>", time: "2pm" },
			   function(data){
					txt2=data;
			   });				
			$.ajaxSettings.async = true;
			layer.confirm('您即将向经销商兑换 '+txt+' 积分,请确认。当前最高可兑换积分：'+txt2+' 积分。', {
				icon: 3,
				title: '积分兑换提示'
			},
			function(index) {
			if(txt===undefined){
				layer.msg("请输入要兑换的积分。");
				return;
			}
			if(Number(txt)<=0){
				layer.msg("要兑换的积分必须大于0。");
				return;
			}	
			if(Number(txt)>Number(txt2)){
				layer.msg("您现有积分不足，请重新输入要兑换的积分。");
				return;
			}
			  admin.req({
				url: layui.setter.base + 'lib/reg.asp?action=jfdh&jxs=<%=easp.var("jxs")%>' 
				,data: obj.field
				,done: function(res){

				if(res.msg=="成功"){
				  layer.msg('积分兑换成功。', {
					offset: '15px'
					,icon: 1
					,time: 1000
				  }, function(){
					//location.href = '../'; //后台主页
				  });
				}else
				{
				  layer.msg('积分申领失败！请联系管理员。', {
					offset: '15px'
					,icon: 1
					,time: 1000
				  }, function(){
					//location.href = '../'; 
				  });	
				}		

				}
			  });			
				
			});	
	
	

      
    });  
  });
  </script>
</body>
</html>